package com.jdzy.student.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jdzy.model.common.vos.ResultA;
import com.jdzy.model.common.vos.ResultCodeEnum;
import com.jdzy.model.teacher.pojos.SysRole;
import com.jdzy.model.teacher.pojos.SysUser;
import com.jdzy.student.service.SysUserService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@Api(value = "教师的controller类")
@CrossOrigin(allowCredentials = "true" , allowedHeaders = "*")
@RequestMapping(value = "/api/system/sysUser")
public class SysUserController {
    @Autowired
    private SysUserService sysUserService ;
//    @GetMapping(value = "/findByPage/{pageNum}/{pageSize}")
//    public ResultA<PageInfo<SysRole>> findByPage(SysUserDto sysUserDto ,
//                                                @PathVariable(value = "pageNum") Integer pageNum ,
//                                                @PathVariable(value = "pageSize") Integer pageSize) {
//        //调用业务层传入参数获取分页数据
//        PageInfo<SysUser> pageInfo = sysUserService.findByPage(sysUserDto , pageNum , pageSize) ;
//        return ResultA.build(pageInfo , ResultCodeEnum.SUCCESS) ;
//    }

    //根据分页查询所有用户
    @GetMapping(value = "findByPage")
    public ResultA<IPage<SysRole>> findByPage(
            @RequestParam long current, @RequestParam long size) {
        //调用业务层传入参数获取分页数据
        IPage<SysUser> pageInfo = sysUserService.findByPage(current, size);
        return ResultA.build(pageInfo , ResultCodeEnum.SUCCESS) ;
    }
    //保存用户
    @PostMapping(value = "/saveSysUser")
    public ResultA saveSysUser(@RequestBody SysUser sysUser) {
        sysUserService.saveSysUser(sysUser) ;
        return ResultA.build(null , ResultCodeEnum.SUCCESS) ;
    }
    //修改用户
    @PutMapping(value = "/updateSysUser")
    public ResultA updateSysUser(@RequestBody SysUser sysUser) {
        sysUserService.updateSysUser(sysUser) ;
        return ResultA.build(null , ResultCodeEnum.SUCCESS) ;
    }

    //删除用户
    @DeleteMapping(value = "/deleteById/{userId}")
    public ResultA deleteById(@PathVariable(value = "userId") Long userId) {
        sysUserService.deleteById(userId) ;
        return ResultA.build(null , ResultCodeEnum.SUCCESS) ;
    }
}
